package cn.controller;

import cn.domain.BResult;
import cn.domain.Users;
import cn.service.UsersService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UsersService usersService;

    @PostMapping("login")
    public BResult login(@RequestBody Users users){

        LambdaQueryWrapper<Users> usersLambdaQueryWrapper = new LambdaQueryWrapper<>();

        usersLambdaQueryWrapper.eq(Users :: getUsername,users.getUsername());

        Users one = usersService.getOne(usersLambdaQueryWrapper);

        if(one == null){

            return BResult.error("用户名不存在");

        }

        String password = users.getPassword();

        String password1 = one.getPassword();

        if(!password1.equals(password)){

            return BResult.error("密码错误");

        }

        return BResult.success("登录成功");

    }

}
